<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增参数')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <style>
        .file-input .theme-fas .file-input-ajax-new {
            width: 70%;
            margin-left: 150px;
        }

        .fileinput-upload-button {
            display: none !important;
        }

    </style>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-config-add" name="form-config-add" enctype="multipart/form-data">

        <div class="form-group">
            <div style="width: 73%;margin-left: 130px">
                <label class="font-noraml">附件:</label>
                <div class="file-loading">
                    <input class="file" type="file" id="filePath" multiple data-min-file-count="1" data-theme="fas">
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">描述：</label>
            <div class="col-sm-8">
                <textarea id="describe" name="describe" class="form-control" placeholder="简述当前形象进度、关键工序施工情况、主要危险源监控情况、巡检及旁站监督记录等，每周五之前填报"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script type="text/javascript">
    var prefix = ctx + "danManage";

    /* 获取服务端返回变量 */
    var danId = [[${danId}]];

    /* 提交 */
    function submitHandler() {
        var formData = new FormData();
        if ($('#filePath')[0].files[0] == null) {
            $.modal.alertWarning("请先选择文件路径");
            return false;
        }

        if ($('#filePath')[0].files[1] != null) {
            $.modal.alertWarning("仅支持单文件上传");
            return false;
        }

        if ($("#describe").val() == null || $("#describe").val() == '') {
            $.modal.alertWarning("请填写描述信息");
            return false;
        }

        formData.append('danId', danId);
        formData.append('describe', $("#describe").val());
        formData.append('file', $('#filePath')[0].files[0]);
        $.ajax({
            url: prefix + "/upload",
            type: 'post',
            cache: false,       //上传文件不需要缓存
            data: formData,
            processData: false, //data值是FormData对象，不需要对数据进行处理
            contentType: false, //contentType值，因为是由<form>表单构造的FormData对象，且已经声明了属性enctype="multipart/form-data"，所以这里设置为false。
            dataType: "json",
            success: function (result) {
                $.operate.successCallback(result);
            }
        });
    }
</script>
</body>
</html>
